package com.why.blog.login;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.why.blog.dao.mapper.HaloUserMapper;
import com.why.blog.entity.HaloUser;
import com.why.blog.entity.JwtUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private HaloUserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        HaloUser user = userMapper.selectOne(new QueryWrapper<HaloUser>().eq("user_name",s));
        return new JwtUser(user);
    }
}
